//////////////////////////////////////////////////////////////////////////////////
//
//	Who's Spectating Me
//		- Version 1.1
//		- 03.23.2008
//		- diamond-optic
//
//////////////////////////////////////////////////////////////////////////////////
//
// Information:
//
// - Prints to your chat a list of players that are spectating you
//
//////////////////////////////////////////////////////////////////////////////////
//
// COMMAND/BIND:
//
// 	amx_whospecme		//print to chat who, if anyone, is spectating you
//
//////////////////////////////////////////////////////////////////////////////////
//
// EXTRA:
//
//	- WHOSPECME_ADMIN define controls the admin level used (default: immunity)
//
//////////////////////////////////////////////////////////////////////////////////
//
// Changelog:
//
// - 12.05.2006 Version 1.0
//	Initial Release
//
// - 03.23.2008 Version 1.1
//	Updated public cvar format
//	Cleaned up code a little bit
//
//////////////////////////////////////////////////////////////////////////////////

#include <amxmodx>
#include <amxmisc>
#include <fakemeta>

#define VERSION "1.1"
#define SVERSION "v1.1 - by diamond-optic (www.AvaMods.com)"

#define WHOSPECME_ADMIN		ADMIN_LEVEL_B	//Admin Level

public plugin_init()
{
	register_plugin("Who's Spectating Me",VERSION,"diamond-optic")
	register_cvar("amx_whospecme_stats",SVERSION,FCVAR_SERVER|FCVAR_SPONLY)
	
	register_concmd("amx_whospecme","funcMySpecs",WHOSPECME_ADMIN,"Shows you who is spectating you")
}

public funcMySpecs(id,level,cid)
{
	if(access(id,WHOSPECME_ADMIN) && is_user_connected(id) && is_user_alive(id))
		{
		new numSpecs
		
		for(new spec = 1; spec <= get_playersnum(); spec++)
			{			
			if(is_user_connected(spec) && !is_user_alive(spec) && !is_user_bot(spec))
				{				
				if(pev(spec,pev_iuser2) == id)
					{
					new spec_name[33]
					get_user_name(spec,spec_name,32)
					
					client_print(id,print_chat,"** ^"%s^" is spectating you! **",spec_name)
					
					numSpecs++
					}
				}
			}
			
		if(!numSpecs)
			client_print(id,print_chat,"** there is no one spectating you! **")
		}
		
	return PLUGIN_HANDLED
}
